import { mysqlTable, varchar, timestamp, int, boolean } from 'drizzle-orm/mysql-core'
import { usersTable } from './user'

// token表定义
export const refreshTokensTable = mysqlTable('refresh_token', {
  id: int().autoincrement().primaryKey(),
  userId: int('user_id')
    .notNull()
    .references(() => usersTable.id, { onDelete: 'cascade' }),
  token: varchar({ length: 500 }).notNull().unique(),
  expiresAt: timestamp('expires_at', { mode: 'date' }).notNull(),
  createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
  isRevoked: boolean('is_revoked').default(false).notNull()
})
